/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.unal.bioingenium.kbmed.text.filter;

import co.edu.unal.bioingenium.kbmed.config.Configuration;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.tartarus.snowball.SnowballProgram;


/**
 *
 * @author Alejandro Riveros Cruz Riveros Cruz
 */
public class Stemmer {

    private SnowballProgram stemmer;

    /**
     * 
     */
    public Stemmer() {
        try {
            Class stemClass = Class.forName("org.tartarus.snowball.ext." + Configuration.LANGUAGE + "Stemmer");
            stemmer = (SnowballProgram) stemClass.newInstance();
        } catch (InstantiationException ex) {
            Logger.getLogger(Stemmer.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(Stemmer.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Stemmer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * 
     * @param word
     * @return
     */
    public String stem(String word) {
        stemmer.setCurrent(word);
        stemmer.stem();
        return stemmer.getCurrent();
    }

}
